if (the mouseCast < 13) or (the mouseCast > 18) then
return
end if
set snr to (the mouseCast - 2) * 2
else
set snr to the clickOn
if the clickOn = 0 then
return
end if
end if
set whichObject to getobjectFromSnr(snr)
handleClickOnNrButton(whichObject)
updateStage()
end
on handleClickOnNrButton nrButton
if currentInputStatus = #waitForOperand1 then
set operand1 to nrButton
pressButton(nrButton)
set currentInputStatus to #waitForOperator
else
if currentInputStatus = #waitForOperand2 then
if nrButton = operand1 then
put "button already pressed"
beep()
else
if (operator = ":") and ((the value of operand1 mod the value of nrButton) <> 0) then
if (the value of nrButton > the value of operand1) and ((the value of nrButton mod the value of operand1) = 0) then
set dummy to nrButton
set nrButton to operand1
set operand1 to dummy
set operand2 to nrButton
pressButton(nrButton)
handleOperation()
set currentInputStatus to #waitForOperand1
if not dividealertGivenP then
alert("You said" && the value of operand2 && " : " && the value of operand1 & ". But that's illegal: no fractions! So I swapped the operands for you.")
set dividealertGivenP to 1
end if
else
alert("Remainder of division must be equal to 0. So, for example, 10 : 2 is legal, but 10 : 3 is illegal.")
end if
else
if (operator = "-") and ((the value of operand1 - the value of nrButton) < 0) then
set dummy to nrButton
set nrButton to operand1
set operand1 to dummy
set operand2 to nrButton
pressButton(nrButton)
handleOperation()
set currentInputStatus to #waitForOperand1
if not minusalertGivenP then
alert("You said" && the value of operand2 && " - " && the value of operand1 & ". But that's illegal: no negative numbers! So I swapped the operands for you.")
set minusalertGivenP to 1
end if
else
if (operator = "-") and ((the value of operand1 - the value of nrButton) = 0) then
alert("Result must be greater than 0.")
else
set operand2 to nrButton
pressButton(nrButton)
handleOperation()
set currentInputStatus to #waitForOperand1
end if
end if
end if
end if
else
if currentInputStatus = #waitForOperator then
unpressButton(operand1)
set currentInputStatus to #waitForOperand1
if the buttonsnr of operand1 <> the buttonsnr of nrButton then
handleClickOnNrButton(nrButton)
else
puppetSound("nrButtonClick")
end if
end if
end if
end if
end
on clickOnOperator
put "clickonoperatr"
if justAborted or menuVisibleP then
return
end if
if calcIsRunningP then
if (the mouseCast < 22) or (the mouseCast > 29) then
return
end if
if the mouseCast < 26 then
set snr to the mouseCast - 17
else
set snr to the mouseCast - 21
end if
else
set snr to the clickOn
if the clickOn = 0 then
return
end if
end if
set tempoperatorindex to snr - zerooperatorsnr
handleClickOnOperator(tempoperatorindex)
put "enter handle with .." & tempoperatorindex
updateStage()
end
on handleClickOnOperator paramIndex
if currentInputStatus = #waitForOperand1 then
put "click on operator but waiting for operand 1"
if operand2index = 0 then
beep()
return
else
set currentRow to getAt(nrbuttontable, currentStep)
set whichObject to getAt(currentRow, operand2index)
handleClickOnNrButton(whichObject)
end if
end if
if currentInputStatus = #waitForOperand2 then
unpressOperatorButton(operatorindex)
set currentInputStatus to #waitForOperator
if operatorindex <> paramIndex then
handleClickOnOperator(paramIndex)
else
puppetSound("operatorButtonClick")
end if
else
set operatorindex to paramIndex
set operator to getAt(operatorList, operatorindex)
pressOperatorButton(operatorindex)
set currentInputStatus to #waitForOperand2
end if
end
on pressOperatorButton operatorindex
set snr to zerooperatorsnr + operatorindex
set the castNum of sprite snr to the castNum of sprite snr - 4
puppetSound("operatorButtonClick")
end
on unpressOperatorButton operatorindex
set snr to zerooperatorsnr + operatorindex
set the castNum of sprite snr to the castNum of sprite snr + 4
end
on handleOperation
set currentRow to getAt(nrbuttontable, currentStep)
set newRow to getAt(nrbuttontable, currentStep + 1)
repeat with i = 1 to nrOfStims
setNrButtonvalue(getAt(newRow, i), the value of getAt(currentRow, i))
setNrButtonVisibleP(getAt(newRow, i), the visibleP of getAt(currentRow, i))
set the visible of sprite (zeroClearsnr + currentStep) to 1
set currentStep to currentStep + 1
if result = targetnr then
userFoundIt(getAt(newRow, operand2index))
end if
end
on calculateResult
set nr1 to the value of operand1
set nr2 to the value of operand2
if operator = "+" then
return nr1 + nr2
else
if operator = "-" then
return nr1 - nr2
else
if operator = "x" then
return nr1 * nr2
else
if operator = ":" then
return nr1 / nr2
end if
end if
end if
end if
end
on showConnectorToResult operand1index, operand2index, operatorindex
if operand1index > operand2index then
set offsetcastnum to 50
else
set offsetcastnum to 60
end if
set whichCast to offsetcastnum + abs(operand1index - operand2index)
set the castNum of sprite connectorsnr to whichCast
set the loc of sprite connectorsnr to the buttonloc of operand2
set the locH of sprite connectorsnr to the locH of sprite connectorsnr - 35
set the locV of sprite connectorsnr to the locV of sprite connectorsnr + 12
set the locH of sprite tempoperatorsnr to the locH of sprite connectorsnr
set the locV of sprite tempoperatorsnr to the locV of sprite connectorsnr
set the castNum of sprite tempoperatorsnr to 65 + operatorindex
updateStage()
add(connectorlocs, the loc of sprite connectorsnr)
add(connectorcastnums, the castNum of sprite connectorsnr)
add(opconnectorcastnums, the castNum of sprite tempoperatorsnr)
end
on hideLastConnector
set the trails of sprite connectorsnr to 0
set the trails of sprite tempoperatorsnr to 0
updateStage()
if currentStep > 2 then
set the loc of sprite connectorsnr to getAt(connectorlocs, currentStep - 2)
set the loc of sprite tempoperatorsnr to the loc of sprite connectorsnr
deleteAt(connectorlocs, currentStep - 1)
set the castNum of sprite connectorsnr to getAt(connectorcastnums, currentStep - 2)
deleteAt(connectorcastnums, currentStep - 1)
set the castNum of sprite tempoperatorsnr to getAt(opconnectorcastnums, currentStep - 2)
deleteAt(opconnectorcastnums, currentStep - 1)
else
set the loc of sprite connectorsnr to heaven
set the loc of sprite tempoperatorsnr to heaven
set connectorlocs to []
set connectorcastnums to []
end if
updateStage()
set the trails of sprite connectorsnr to 1
set the trails of sprite tempoperatorsnr to 1
updateStage()
end
on setAllNrButtonTrails value
repeat with n = 1 to 2 * nrOfStims
set the trails of sprite (zerobuttonsnr + n) to value
end repeat
end
on setAllNrButtonsToDimmed arow, bool
repeat with n = 1 to count(arow)
dimNrButton(getAt(arow, n), bool)
end repeat
end
on clickOnClear
put "clickonclear"
if justAborted or menuVisibleP then
return
end if
set clickedsnr to getClickedClearSnr()
set the castNum of sprite clickedsnr to cast "clearButtonPressed"
updateStage()
if currentInputStatus = #waitForOperand2 then
unpressButton(operand1)
unpressOperatorButton(operatorindex)
else
if currentInputStatus = #waitForOperator then
unpressButton(operand1)
end if
end if
updatescreenIfUserContinuesAFterFoundIt()
set currentInputStatus to #waitForOperand1
set thelastvisibleclearbuttonsnr to zeroClearsnr + currentStep - 1
repeat with snr = thelastvisibleclearbuttonsnr down to clickedsnr
waitawhile(20)
puppetSound("slurp")
handleClear(snr)
end repeat
set operand2index to 0
updateStage()
end
on getClickedClearSnr
if calcIsRunningP then
repeat with n = zeroClearsnr + 1 to zeroClearsnr + nrOfStims
if rollOver(n) then
return n
end if
end repeat
else
set snr to the clickOn
return snr
end if
end
on hideLastClearButton snr
set the visible of sprite snr to 0
set the castNum of sprite snr to cast "clearButtonUnPressed"
end
on handleClear clearbuttonsnr
setAllNrButtonsnrsLocsTo(heaven)
set currentRow to getAt(nrbuttontable, currentStep)
repeat with i = 1 to nrOfStims
setNrButtonVisibleP(getAt(currentRow, i), 1)
end repeat
hideLastConnector()
hideLastClearButton(clearbuttonsnr)
updateStage()
set previousRow to getAt(nrbuttontable, currentStep - 1)
repeat with i = 1 to nrOfStims
showNrButton(getAt(previousRow, i))
applyVisibleP(getAt(previousRow, i))
showNrButtonValue(getAt(previousRow, i))
end repeat
set currentStep to currentStep - 1
updateStage()
end
on setAllNrButtonsnrsLocsTo p
repeat with n = 1 to 2 * nrOfStims
set the loc of sprite (zerobuttonsnr + n) to p
end repeat
end
on clickOnCalculator
if (justAborted and firstabortprocessed) or menuVisibleP then
return
end if
if not calcIsRunningP then
set the castNum of sprite calculatorsnr to cast "bigCalculatorOn"
set the loc of sprite nrOfCalcsSnr to nrOfCalcsLoc
updateStage()
if justAborted then
return
end if
puppetSound("operatorButtonClick")
updateStage()
set calcIsRunningP to 1
set timeOnStartCalculator to the ticks
updateStage()
findsolution()
else
set the castNum of sprite calculatorsnr to cast "bigCalculatorOff"
updateStage()
set calcIsRunningP to 0
waitawhile(60)
if justAborted then
set firstabortprocessed to 1
end if
end if
updateStage()
end
on clickOnClock
if justAborted or menuVisibleP then
return
end if
if clockIsActiveP then
set clockIsActiveP to 0
set the visible of sprite fillbarsnr to 0
set the visible of sprite maxsecssnr to 0
set the visible of sprite timeOutLinesnr to 0
set the castNum of sprite clocksnr to cast "cloud"
else
set the visible of sprite fillbarsnr to 1
set the visible of sprite maxsecssnr to 1
set the visible of sprite timeOutLinesnr to 1
set clockIsActiveP to 1
set the castNum of sprite clocksnr to cast "sun"
resetTheClock()
end if
updateStage()
end
on initRadioButtons
set the checkBoxAccess to 2
set the hilite of cast "60 secs" to 0
set the hilite of cast "120 secs" to 0
set the hilite of cast "180 secs" to 1
set the hilite of cast "240 secs" to 0
set the hilite of cast "6000 secs" to 0
repeat with n = 35 to 40
puppetSprite(n, 1)
set the loc of sprite n to heaven
end repeat
set lastbutton to 77
set nrOfSecsInMAxSecs to 180
put toRoman(nrOfSecsInMAxSecs) into field "maxsecs"
end
on clickOnRadioButton
if justAborted or menuVisibleP then
return
end if
if calcIsRunningP then
if (the mouseCast < 75) or (the mouseCast > 79) then
return
end if
set snr to the mouseCast - 39
else
set snr to the clickOn
end if
if snr <> 0 then
set castn to the mouseCast
set the hilite of cast lastbutton to 0
set the hilite of cast castn to 1
updateStage()
set nrOfSecsInMAxSecs to getAt([60, 120, 180, 240, 6000], castn - 75 + 1)
put toRoman(nrOfSecsInMAxSecs) into field "maxsecs"
set lastbutton to castn
set deadlinePassed to 0
closeRadioButtonWindow()
end if
updateStage()
end
on clickOnMaxSecs
if justAborted or menuVisibleP then
return
end if
openRadioButtonWindow()
end
on openRadioButtonWindow
set the loc of sprite 35 to point(570, 14)
repeat with n = 36 to 40
set the loc of sprite n to point(570, 19 + ((n - 36) * 17))
end repeat
updateStage()
end
on closeRadioButtonWindow
waitawhile(45)
repeat with n = 35 to 40
set the loc of sprite n to heaven
end repeat
end
on resetTheClock
puppetSound("ticktack")
spriteBox(fillbarsnr, the left of sprite fillbarsnr, the top of sprite fillbarsnr, 5 + the left of sprite fillbarsnr, the bottom of sprite fillbarsnr)
set timeAtReset to the ticks
set ticksPassed to 0
set deadlinePassed to 0
set the foreColor of field "maxsecs" to 193
end
on updateFillBar
if not deadlinePassed then
set maxticks to 60 * nrOfSecsInMAxSecs
set ticksPassed to the ticks - timeAtReset
if ticksPassed > maxticks then
timeIsUp()
end if
set newlength to max(5, min(maxlengthFillbar, (ticksPassed + 0.01) / maxticks * maxlengthFillbar))
spriteBox(fillbarsnr, the left of sprite fillbarsnr, the top of sprite fillbarsnr, newlength + the left of sprite fillbarsnr, the bottom of sprite fillbarsnr)
if ticksPassed = (0.90000000000000002 * maxticks) then